﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Common;

/// <summary>
/// A resource bundle
/// </summary>
public class RBBundle
{
    /// <summary>
    /// Gets or sets the ID of the application which contains this bundle.
    /// </summary>
    /// <value>The application ID.</value>
    public string ApplicationID { get; set; }
    /// <summary>
    /// Gets or sets the bundle's ID.
    /// </summary>
    /// <value>The bundle ID.</value>
    public string BundleID { get; set; }
    /// <summary>
    /// Gets or sets the name.
    /// </summary>
    /// <value>The name.</value>
    public string Name { get; set; }

    public RBBundle() {
        ApplicationID = string.Empty;
        BundleID = Utils.GenID(true);
        Name = string.Empty;
    }

    /// <summary>
    /// Initializes a new <see cref="RBBundle"/>.
    /// </summary>
    /// <param name="applicationId">The ID of the application which contains this bundle.</param>
    /// <param name="bundleId">The bundle ID.</param>
    /// <param name="name">The bundle name.</param>
	public RBBundle(string applicationId, string bundleId, string name)
	{
        this.ApplicationID = applicationId;
        this.BundleID = bundleId;
        this.Name = name;
	}

    /// <summary>
    /// Initializes a new <see cref="RBBundle"/>.
    /// </summary>
    /// <param name="reader">The reader containing all fields.</param>
    public RBBundle(DbDataReader reader) {
        if(reader.FieldCount < 3) {
            throw new ArgumentException("Reader must contain all fields");
        }
        this.ApplicationID = reader["application"].ToString();
        this.BundleID = reader["id"].ToString();
        this.Name = reader["name"].ToString();
    }
}
